<?php 
    require 'comm/chkLoginState.php';
    require 'comm/header.php';
    $com = new DB();
    if (!empty($_GET['id'])){
        $id = $_GET['id'];
        $sql = " where admin_id = ".$id;
        $arr = $com->select('admin_info',$sql);
    }else if($_POST){
        $id = !empty($_POST['id'])?$_POST['id']:'';
        $name = !empty($_POST['user'])?$_POST['user']:'';
        $pwd = !empty($_POST['password'])?$_POST['password']:'';
        $arr = array();
        if ($name){$arr['admin_name'] = $name;}
        if ($pwd){$arr['admin_pwd']=$pwd;}
        $where = " WHERE (`admin_id`='".$id."')";
        $re = $com->update('admin_info',$arr,$where);
        if($re){
            echo "<script type='text/javascript'>alert('sussess');window.location.href='admin_index.php'</script>";
        }else{
            echo "<script type='text/javascript'>alert('fail');window.location.href='admin_update.php?id=".$id."'</script>";
        }
    }

?>
<div class="card">
              <div class="card-header">
                        <strong>修改</strong>
              </div>
             <form action="admin_update.php" method="post" class="form-horizontal ">
                   <div class="card-block">
                        <div class="form-group row">
                            <label class="col-md-3 form-control-label" for="hf-email">用户名</label>
                                            <div class="col-md-9">
                                                <input type="text" id="user" name="user" class="form-control" placeholder="Enter user.." value ="<?php echo $arr['admin_name']?>">
                                                <span class="help-block">Please enter your user</span>
                                            </div>
                                        </div>
                                        <div class="form-group row">
                                            <label class="col-md-3 form-control-label" for="hf-password">密码</label>
                                            <div class="col-md-9">
                                                <input type="text" id="password" name="password" class="form-control" placeholder="Enter Password.." value ="<?php echo $arr['admin_pwd']?>">
                                                <span class="help-block">Please enter your password</span>
                                            </div>
                                        </div>
                                   
                                </div>
                                <div class="card-footer">
                                    <input type = "submit" name= 'sub' value='submit'>
                                    <input type = "hidden" name = 'id' value="<?php echo $id;?>" >
<!--                                     <button type="submit" class="btn btn-sm btn-primary"><i class="fa fa-dot-circle-o"></i> Submit</button> -->
<!--                                     <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> Reset</button> -->
                                </div>
                                 </form>
                            </div>
                            <?php require 'comm/footer.php';?>